<?php
require_once substr(dirname(__FILE__),0,-1).'sub/init.php';
if(@!in_array('hn',$navarr))exit('该功能已关闭');
require_once ZEAI.'sub/conn.php';
if (!ifint($fid))json_exit(array('flag'=>0,'msg'=>'红娘ID错误'));
if(is_mobile())header("Location: ".mHref('hongniang_detail',$fid));
if($submitok == 'ajax_join_update'){
	$hid=$fid;
	if(!ifint($hid))json_exit(array('flag'=>0,'msg'=>'红娘ID错误'));
	if(!iflogin()){
		$jumpurl=a('{"kind":"hongniang","id":"'.$hid.'"}');
		json_exit(array('flag'=>'nologin','jumpurl'=>$jumpurl));
	}
	//当前红娘
	$rowf = $db->ROW(__TBL_CRM_HN__,"id,truename,agentid,agenttitle,openid,subscribe","ifwebshow=1 AND flag=1 AND id=".$hid,'name');
	if (!$rowf)json_exit(array('flag'=>0,'msg'=>'红娘不存在'));
	$hn_truename   = dataIO($rowf['truename'],'out');
	$hn_agentid    = intval($rowf['agentid']);
	$hn_agenttitle = $rowf['agenttitle'];
	$hn_openid     =  $rowf['openid'];
	$hn_subscribe  =  $rowf['subscribe'];
	//我
	$row2 = $db->ROW(__TBL_USER__,"nickname,sex,admid,admname","id=".$cook_uid,"name");
	if ($row2){
		$cook_nickname= trimhtml(dataIO($row2['nickname'],'out'));
		$cook_admid   = intval($row2['admid']);
		$cook_sex     = intval($row2['sex']);
		$cook_admname = dataIO($row2['admname'],'out');
		if($cook_admid>0)json_exit(array('flag'=>0,'msg'=>'您已经被红娘【'.$cook_admname.' -> ID:'.$cook_admid.'】接洽，正在服务中'));
		$db->query("UPDATE ".__TBL_USER__." SET admid=".$hid.",admname='$hn_truename',admtime=".ADDTIME.",agentid=".$hn_agentid.",agenttitle='$hn_agenttitle' WHERE (flag=1 OR flag=-2) AND id=".$cook_uid);
		//通知红娘
		$sex_title = ($cook_sex == 1)?'他':'她';
		$T = '【'.$cook_nickname.' uid:'.$cook_uid.'】想委托您为'.$sex_title.'服务';
		$C = $T.'，已经在你名下，成为了您的客户，请到CRM后台进行联系跟进服务';
		//$db->SendTip($hn_uid,$T,dataIO($C,'in'),'sys');
		//微信通知
		if ($hn_subscribe == 1 && !empty($hn_openid)){
			//客服通知
			$content = urlencode($C);
			$ret = @wx_kf_sent($hn_openid,$content,'text');
			$ret = json_decode($ret);
			//模版通知
			if ($ret->errmsg != 'ok'){
				$keyword1  = $content;
				$keyword3  = urlencode($_ZEAI['siteName']);
				@wx_mb_sent('mbbh=ZEAI_ADMIN_INFO&openid='.$hn_openid.'&keyword1='.$keyword1.'&keyword3='.$keyword3.'&time='.ADDTIME.'&first='.$first.'&remark='.$remark.'&url=');
			}
		}
	}
	json_exit(array('flag'=>1,'msg'=>'申请已发送，请等待【'.$hn_truename.'】接洽～'));
/************************ BBS ***********************/
exit;}elseif($submitok == 'ajax_hnBBS_update'){
	if(!ifint($fid))json_exit(array('flag'=>0,'msg'=>'红娘ID错误'));
	if ($cook_content == $content && !empty($content))json_exit(array('flag'=>0,'msg'=>'请不要重复发布'));
	$$rtn='json';$chk_u_jumpurl=Href('hongniang',$fid);
	require_once ZEAI.'p/my_chkuser.php';
	//
	if ( (str_len($content)>10000 || str_len($content)<1) )json_exit(array('flag'=>0,'msg'=>'评价内容请控制在1~1000字节以内'));
	if ($kind != 1 && $kind != 2 && $kind != 3)json_exit(array('flag'=>0,'msg'=>'请打分【好评－中评－差评】'));
	switch ($kind) {
		case 1:$sql  = " ,pj_good=pj_good+1 ";break;
		case 2:$sql  = " ,pj_normal=pj_normal+1 ";break;
		case 3:$sql  = " ,pj_bad=pj_bad+1 ";break;
	}
	$row = $db->ROW(__TBL_HN_BBS__,"id","uid=".$cook_uid." AND hid=".$fid);
	if ($row)json_exit(array('flag'=>0,'msg'=>'您已经评价过了～请不要重复评价'));
	
	$row = $db->ROW(__TBL_USER__,"nickname,sex,photo_s,photo_f","id=".$cook_uid." AND admid=".$fid);
	if ($row){
		$content = dataIO($content,'in',1000);
		$db->query("INSERT INTO ".__TBL_HN_BBS__." (uid,hid,content,addtime,pjkind) VALUES ($cook_uid,'$fid','$content',".ADDTIME.",$kind)");
		$db->query("UPDATE ".__TBL_CRM_HN__." SET bbsnum=bbsnum+1 ".$sql." WHERE id=".$fid);
		setcookie("cook_content",$content,time()+720000,"/",$_ZEAI['CookDomain']);
		json_exit(array('flag'=>1,'msg'=>'评价成功','C'=>$CC,'pjkind'=>$pjkind));
	}else{
		json_exit(array('flag'=>0,'msg'=>'您没有找Ta牵线，无法评价哦'));
	}
}elseif($submitok == 'ajax_iflogin'){
	if(!iflogin() || !ifint($cook_uid))json_exit(array('flag'=>'nologin','msg'=>'请先登录后再来申请','jumpurl'=>Href('hongniang',$fid)));
	json_exit(array('flag'=>1));
}
$row = $db->ROW(__TBL_CRM_HN__,"sex,qq,weixin,mob,path_s,ewm,truename,sex,aboutus,title,pj_good,pj_normal,pj_bad,click","flag=1 AND id=".$fid,"name");
if ($row){
	$truename = trimhtml(dataIO($row['truename'],'out',7));
	$aboutus  = trimhtml(dataIO($row['aboutus'],'out'));
	$title    = trimhtml(dataIO($row['title'],'out'));
	$pj_good  = $row['pj_good'];
	$pj_normal= $row['pj_normal'];
	$pj_bad   = $row['pj_bad'];
	$unum     = $row['unum'];
	$bbsnum   = $row['bbsnum'];
	$click    = $row['click'];
	$sex      = $row['sex'];
	$path_s   = $row['path_s'];
	$ewm      = $row['ewm'];
	$qq = dataIO($row['qq'],'out');
	$weixin = dataIO($row['weixin'],'out');
	$mob = dataIO($row['mob'],'out');
	//
	$sex_title= ($sex == 1)?'他':'她';
	$path_s_url = (!empty($path_s))?UP.smb($path_s,'b'):RES.'photo_m'.$sex.'.png';
	$ewm_str    = (!empty($ewm))?'<img src="'.UP.$ewm.'">':'暂无';
	$sexbg   = (empty($path_s))?' class="sexbg'.$sex.'"':'';
	$join_title = '～ 找'.$sex_title.'牵线 ～';	

	$db->query("UPDATE ".__TBL_CRM_HN__." SET click=click+1 WHERE id=".$fid);
	$unum = $db->COUNT(__TBL_USER__,"admid=".$fid);
	if (ifint($cook_uid)){
		$row = $db->ROW(__TBL_USER__,"crm_flag","id=".$cook_uid." AND admid=".$fid);
		if ($row){
			$joinclass  = ' class="addmeed"';	
			switch ($row[0]) {
				case 1:$join_title  = '正在服务中';break;
				case 2:$join_title  = '服务跟进中';break;
				case 3:$join_title  = '服务成功';break;
			}
		}
	}
}else{alert('暂无信息','-1');}
require_once ZEAI.'cache/udata.php';
$nav='hongniang';$up2 = UP;
?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $truename;?>_红娘_<?php echo $_ZEAI['siteName'];?></title>
<link href="<?php echo RES;?>p/css/p.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>p/css/hongniang.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>p/js/p.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<style>
.dtlbanner{background:url("<?php echo RES;?>p/img/hnbanner2.jpg");}
.dtl_ubox{background:url("<?php echo RES;?>p/img/ubg.jpg")}
</style>
</head>
<body>
<?php
require_once ZEAI.'p/top2.php';
$hn_join_btnT='<span class="ico">&#xe635; 找'.$sex_title.'牵线</span>';
$hn_join_btnCls='';
if(ifint($cook_uid)){
	$row = $db->ROW(__TBL_USER__,"admid","id=".$cook_uid,"name");
	if ($row){
		$cook_admid = intval($row['admid']);
		if($cook_admid==$fid){
			$hn_join_btnT='<span class="ico">&#xe643; 服务中</span>';
			$hn_join_btnCls=' class="doing"';
		}
	}
}?>
<div class="dtlbannerbox">
    <div class="dtlbanner"></div>
    <div class="hninfo S5">
    	<p style="background-image:url(<?php echo $path_s_url; ?>)"<?php echo $sexbg; ?>></p>
        <em>
            <div class="title">
				<h2><?php echo $truename;?><span><i class="ico">&#xe643;</i><font><?php echo $click;?></font></span></h2>
                <div class="pj">
                    <a href="#content">会员<font id="hn_unum"><?php echo $unum; ?></font>个</a>
                    <a href="#content">好评<font id="hn_pjkind1"><?php echo $pj_good; ?></font></a>
                    <a href="#content">中评<font id="hn_pjkind2"><?php echo $pj_normal; ?></font></a>
                    <a href="#content">差评<font id="hn_pjkind3"><?php echo $pj_bad; ?></font></a>
                </div>
                <div class="titlestr"><?php echo $title;?></div>
                <div class="aboutus"><?php echo $aboutus; ?></div>
            </div>
        </em>
        <a id="hn_join_btn"<?php echo $hn_join_btnCls;?>><?php echo $hn_join_btnT;?></a>
    </div>
</div>
<div class="clear"></div>
<div class="dtl_contactbox">
	<h1>联系红娘</h1>
	<div class="dtl_contact">
        <li><i class="ico telico">&#xe68b;</i><span><?php echo $mob; ?>&nbsp;</span><font>红娘热线</font></li>
        <li><i class="ico qqico">&#xe623;</i><span><?php echo $qq; ?>&nbsp;</span><font>红娘QQ</font></li>
        <li><i class="ico wxico">&#xe607;</i><span><?php echo $weixin; ?>&nbsp;</span><font>红娘微信</font></li>
        <div class="hnewm"><p><?php echo $ewm_str; ?></p><h6>微信扫码加红娘微信</h6></div><div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>
<div class="dtl_ubox">
	<h1>这些会员正在委托<?php echo $sex_title; ?></h1>
	<div class="list" id="ulist">
		<?php 
        $rt=$db->query("SELECT id,sex,grade,photo_s,photo_f,areatitle,birthday,job,pay,love,RZ,heigh,photo_ifshow FROM ".__TBL_USER__." WHERE flag=1 AND admid=".$fid." ORDER BY refresh_time DESC LIMIT 100");
        $total = $db->num_rows($rt);
        if ($total > 0) {
            $page_skin='4_yuan';$pagemode=4;$pagesize=20;$page_color=$_ZEAI['mob_mbcolor'];require_once ZEAI.'sub/page.php';
            for($i=1;$i<=$total;$i++) {
                $rows = $db->fetch_array($rt,'name');
                if(!$rows)break;
                $uid      = $rows['id'];
                //$nickname = dataIO($rows['nickname'],'out');
                $sex      = $rows['sex'];
                $love     = $rows['love'];
                $grade    = $rows['grade'];
                $photo_s  = $rows['photo_s'];
                $photo_f  = $rows['photo_f'];
                $areatitle= $rows['areatitle'];
                $birthday = $rows['birthday'];
                $job      = $rows['job'];
                $pay      = $rows['pay'];
                $RZ       = $rows['RZ'];
                $heigh    = $rows['heigh'];
                $photo_ifshow = $rows['photo_ifshow'];
                //$nickname = (empty($nickname))?'uid:'.$uid:$nickname;
                $nickname = '编号：'.$uid;
                //
                $birthday_str = (getage($birthday)<=0)?'':getage($birthday).'岁 ';
                $job_str      = (empty($job))?'':udata('job',$job).' ';
                $pay_str      = (empty($pay))?'':udata('pay',$pay).'/月'.' ';
                $love_str     = (empty($love))?'':udata('love',$love).' ';
                $heigh_str    = ($heigh>140)?$heigh.'cm ':'';
                $aARR = explode(' ',$areatitle);
                $areatitle_str = (empty($aARR[1]))?'':$aARR[1];
                $areatitle_str  = str_replace("不限","",$areatitle_str);
				$photo_m_url = photo_s_out('{"smb":"m","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"url"}');				
                $sexbg      = (empty($photo_s) || $photo_f==0)?' class="m sexbg'.$sex.'"':' class="m"';
                $echo .= '<li>';
                //$uhref = Href('u',$uid);
                $uhref = Href('kefu');
                $echo .= '<a href="'.$uhref.'" class="mbox" target="_blank">';
                $echo .= '<p value="'.$photo_m_url.'"'.$sexbg.'></p>';
                $echo .= '<em><span>'.$love_str.'</span><span>'.$job_str.'</span><span>'.$pay_str.'</span><span>'.$areatitle.'</span></em>';
                $echo .= '<b>联系Ta</b>';
                $echo .= '</a>';
                $echo .= '<a href="'.$uhref.'" target="_blank"><h4>'.$nickname.'</h4></a>';
				$echo .= '<h5>'.$birthday_str.$heigh_str.$job_str.$areatitle_str.'</h5>';
                $echo .= '</li>';
            }
            echo $echo;
        }else{
            echo '<br>'.nodatatips('暂时还没有会员找'.$sex_title.'牵线');
        }
        ?>    
    </div>
</div>
<div class="dtl_bbs">
	<h1>服务评价</h1>
    <div  class="dtl_bbs_li">
	<!-- 留言开始 -->
        <div id="hn_bbs_listbox">
            <?php
            $rt=$db->query("SELECT a.nickname,a.sex,a.grade,a.photo_s,a.photo_f,a.flag,a.photo_ifshow,b.* FROM ".__TBL_USER__." a,".__TBL_HN_BBS__." b WHERE a.id=b.uid AND b.hid=".$fid." ORDER BY b.id");
            $total = $db->num_rows($rt);
            if($total>0){
            for($i=1;$i<=$total;$i++) {
                $rows = $db->fetch_array($rt,'name');
                if(!$rows) break;
                $sex           = $rows['sex'];
                $grade         = $rows['grade'];
                $nickname      = dataIO($rows['nickname'],'out');
                $photo_s       = $rows['photo_s'];
                $photo_f       = $rows['photo_f'];
                $uflag         = $rows['flag'];
                $photo_ifshow  = $rows['photo_ifshow'];
				$photo_s_url = photo_s_out('{"smb":"s","sex":"'.$sex.'","photo_s":"'.$photo_s.'","photo_f":"'.$photo_f.'","photo_ifshow":"'.$photo_ifshow.'","uflag":"'.$uflag.'","outkind":"url"}');				
                $content       = dataIO($rows['content'],'out');
                $content2      = dataIO($rows['content2'],'out');
                $content2_str  = (!empty($content2))?'<div class="hnhf">红娘回复：'.$content2.'</div>':'';
                $flag          = $rows['flag'];
                $pjkind        = $rows['pjkind'];
                switch ($pjkind){
                    case 1:$pjkind_t = '<span class="pjkind k1">好评</span>';break;
                    case 2:$pjkind_t = '<span class="pjkind k2">中评</span>';break;
                    case 3:$pjkind_t = '<span class="pjkind k3">差评</span>';break;
                }?>
            <table class="table li"><tr><td valign="top" class="liL"><img src="<?php echo $photo_s_url; ?>"<?php echo $sexbg; ?>></td>
            <td valign="top" class="liR">
            <table class="table nickname"><tr>
            <td align="left" class="S14"><?php echo $nickname; ?>　评价于<?php echo date_str($rows['addtime']); ?></td>
            <td align="right" class="lou"><span><?php echo $i;?></span>楼</td>
            </tr></table>
            <div class="C">
                <?php
                echo $pjkind_t;
                if ($flag == 1){echo $content.$content2_str;}else{echo'<font>该评价已被冻结或删除！</font>';}
                ?>
            </div>
            </td></tr></table>
            <?php }}else{echo '<br>'.nodatatips('暂无评价');} ?>  
        </div>
        <form id="WwW_Zeai_CN_hnBBS" class="bmform">
        <textarea id="content" name="content" placeholder="我想说两句...　请如实评价~~" class="textarea"></textarea>
        <div class="pjform"><span>服务打分</span>
            <input type="radio" name="kind" id="kind1" class="radioskin" value="1"><label for="kind1" class="radioskin-label"><i class="i2"></i><b>好评</b></label>
            <input type="radio" name="kind" id="kind2" class="radioskin" value="2"><label for="kind2" class="radioskin-label"><i class="i2"></i><b>中评</b></label>
            <input type="radio" name="kind" id="kind3" class="radioskin" value="3"><label for="kind3" class="radioskin-label"><i class="i2"></i><b>差评</b></label>
        </div>
        <input type="button" class="btn size4 HONG2" value=" 发表评价 " id="hn_bbs_btn" />
        <input type="hidden" name="fid" id="fid" value="<?php echo $fid; ?>">
        <input type="hidden" name="i" value="<?php echo $total; ?>">
        <input type="hidden" name="submitok" value="ajax_hnBBS_update">        
        </form>
    </div>
    <!-- 留言结束 QQ797311-->
</div>
<div class="clear"></div>
<script>var supdes,fid=<?php echo intval($fid);?>;</script>
<script src="<?php echo RES;?>p/js/hongniang_detail.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>
hn_join_btn.onclick=function(){hn_join_btnFn();}
function hn_join_btnFn(){
	zeai.confirm('确定【<?php echo $truename;?>】为您服务么？选定后将不能更换',function(){
		zeai.ajax({url:HOST+'/p/hongniang_detail'+zeai.extname,js:1,data:{submitok:'ajax_join_update',fid:<?php echo $fid;?>}},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(rs.msg,{time:3});
			if(rs.flag==1){setTimeout(function(){location.reload(true);},3000);}
		});
	});
}
</script>
<?php require_once ZEAI.'p/bottom.php';?>